/*
 * Copyright (c) 2015 qunar. All Rights Reserved.
 */
package com.guoyu.project.common.utils;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author: libo Date: 15-6-4 Time: 下午10:11
 * @version: \$Id$
 */
public final class Base64Utils {

    /**
     * 加密
     * 
     * @param salt
     * @param password
     * @return
     */
    public final static String encode(String salt, String password) {
        return Base64.encodeBase64String((DigestUtils.md5Hex(salt) + password).getBytes());
    }

    /**
     * 解密
     * 
     * @param salt
     * @param ciphertext
     * @return
     */
    public final static String decode(String salt, String ciphertext) {
        String saltPassword = StringUtils.newStringUtf8(Base64.decodeBase64(ciphertext));
        return org.apache.commons.lang3.StringUtils.substringAfter(saltPassword, DigestUtils.md5Hex(salt));
    }
}
